Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
es6-module-transpiler
Advanced tools
es6-module-transpiler is an experimental compiler that allows you to write your JavaScript using a subset of the current ES6 module syntax, and compile it into various formats.
ES6 Module Transpiler is an experimental compiler that allows you to write your JavaScript using a subset of the current ES6 module syntax, and compile it into AMD or CommonJS modules.
WARNING: The ES6 module syntax is still undergoing a lot of churn, and will likely change before final approval.
ES6 Module Transpiler will track ES6 syntax, and not attempt to maintain backwards compatibility with syntax that ultimately did not succeed as part of ES6.
This compiler provides a way to experiment with ES6 syntax in real world scenarios to see how the syntax holds up. It also provides a nicer, more declarative way to write AMD (or CommonJS) modules.
See the CHANGELOG for the latest updates.
The easiest way to use the transpiler is from an existing build tool. There several plugins developed for different build tools:
The transpiler can be used directly from the command line:
$ npm install -g es6-module-transpiler
$ compile-modules convert < foo.js
Here is the basic usage:
compile-modules convert -I lib -o out FILE [FILE…]
You can also use the transpiler as a library:
var transpiler = require('es6-module-transpiler');
var Container = transpiler.Container;
var FileResolver = transpiler.FileResolver;
var BundleFormatter = transpiler.formatters.bundle;
var container = new Container({
resolvers: [new FileResolver(['lib/'])],
formatter: new BundleFormatter()
});
container.getModule('index');
container.write('out/mylib.js');
Again, this syntax is in flux and is closely tracking the module work being done by TC39.
There are two types of exports. Named exports like the following:
// foobar.js
var foo = 'foo', bar = 'bar';
export { foo, bar };
This module has two named exports, foo
and bar
.
You can also write this form as:
// foobar.js
export var foo = 'foo';
export var bar = 'bar';
Either way, another module can then import your exports like so:
import { foo, bar } from 'foobar';
console.log(foo); // 'foo'
You can also export a default export. For example, an ES6ified jQuery might look like this:
// jquery.js
var jQuery = function() {};
jQuery.prototype = {
// ...
};
export default jQuery;
Then, an app that uses jQuery could import it with:
import $ from 'jquery';
The default export of the "jquery" module is now aliased to $
.
A default export makes the most sense as a module's "main" export, like the
jQuery
object in jQuery. You can use default and named exports in parallel.
module
Whereas the import
keyword imports specific identifiers from a module,
the module
keyword creates an object that contains all of a module's
exports:
module foobar from "foobar";
console.log(foobar.foo); // "foo"
In ES6, this created object is read-only, so don't treat it like a mutable namespace! NOTE: This syntax especially may be removed or modified before ES6 is finalized!
import "foo";
A "bare import" that doesn't import any identifiers is useful for executing side effects in a module. For example:
// alerter.js
alert("alert! alert!");
// alertee.js
import "alerter"; // will pop up alert box
This is super important:
Default exports bind to an identifier on the module called default
!
Internally, the transpiler will use this default identifer when importing, but
any outside consumer needs to be aware that it should use the default
key and
not the module itself. For example, a CommonJS consumer should look like this:
var $ = require('jquery')['default'];
Add this project to your application's package.json by running this:
$ npm install --save es6-module-transpiler
Or install it globally:
$ npm install -g es6-module-transpiler
Thanks to Yehuda Katz for js_module_transpiler, the library on which this one is based. Thanks to Dave Herman for his work on ES6 modules. Thanks to Erik Bryn for providing the initial push to write this library. Thanks to Domenic Denicola & Thomas Boyt for their efforts to make this project even better. And finally thanks to the JavaScript community at Square for helping to write and release this library.
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)Any contributors to the master es6-module-transpiler repository must sign the Individual Contributor License Agreement (CLA). It's a short form that covers our bases and makes sure you're eligible to contribute.
When you have a change you'd like to see in the master repository, send a pull request. Before we merge your request, we'll make sure you're in the list of people who have signed a CLA.
Thanks, and enjoy living in the ES6 future!
v0.6.2 <span class="release-date">(2014-08-20)</span>
FAQs
es6-module-transpiler is an experimental compiler that allows you to write your JavaScript using a subset of the current ES6 module syntax, and compile it into various formats.
The npm package es6-module-transpiler receives a total of 284 weekly downloads. As such, es6-module-transpiler popularity was classified as not popular.
We found that es6-module-transpiler demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.